package cn.gjculture.shopping.api.controller;

import cn.gjculture.shopping.api.entity.Brand;
import cn.gjculture.shopping.api.entity.PageInfo;
import cn.gjculture.shopping.api.entity.Return;
import cn.gjculture.shopping.api.service.BrandService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/brand")
public class BrandController {

    @Autowired
    BrandService brandService;

    @ApiOperation(value = "获取品牌列表", notes = "获取品牌列表")
    @GetMapping
    public Return<List<Brand>> query(PageInfo pageInfo) {
        Return<List<Brand>> ret = new Return<>();
        List<Brand> brands = brandService.query();
        ret.setData(brands);
        return ret;
    }

    @ApiOperation(value = "获取品牌", notes = "根据品牌ID获取品牌")
    @ApiImplicitParam(name = "brandId", value = "活动ID", required = true, dataType = "String",paramType = "path")
    @GetMapping(value = "/{brandId}")
    public Return<Brand> queryById(@PathVariable(value = "brandId") String brandId) {
        Return<Brand> ret = new Return<>();
        Brand brand = brandService.queryById(brandId);
        ret.setData(brand);
        return ret;
    }

    @PutMapping
    public Return update(Brand brand){
        Return ret=new Return();
        if(brandService.update(brand)>0){
            ret.getCommon().setRet(true);
        }
        return ret;
    }


    @PostMapping
    public Return save(Brand brand){
        Return ret=new Return();
        if(brandService.save(brand)>0){
            ret.getCommon().setRet(true);
        }
        return ret;
    }

    @DeleteMapping(value = "/{brandId}")
    public Return delete(@PathVariable(value = "brandId") String brandId){
        Return ret=new Return();
        if(brandService.delete(brandId,ret)>0){
            ret.getCommon().setRet(true);
        }
        return ret;
    }


}
